#include<iostream>
#include<queue>
#include<cstring>
using namespace std;


//horizontal横
//vertical 纵
//coordinates坐标
//labyrinth
typedef pair<int,int> PII;
const int N=35;
char labyrinth[N][N];
int stepcnt[N][N];

int MoveX[4]={-1,1,0,0};
int MoveY[4]={0,0,-1,1};
int n,m;

int bfs(int x,int y)
{
	queue<PII> q;
	q.push({x,y});
	stepcnt[x][y]=0;
	int exitcnt=0;
	int stepcnts=-1;
	while(q.size())
	{
		auto coordinates=q.front();q.pop();
		int horizontal=coordinates.first;
		int vertical=coordinates.second;

		for(int i=0;i<4;i++)
		{
			int newHorizontal=horizontal+MoveX[i];
			int newVertical=vertical+MoveY[i];

			if(newHorizontal>=1&&newHorizontal<=n
				&&newVertical>=1&&newVertical<=m
				&&labyrinth[newHorizontal][newVertical]!='*'
				&&stepcnt[newHorizontal][newVertical]==-1)
			{
				if(labyrinth[newHorizontal][newVertical]=='.')
					q.push({newHorizontal,newVertical});
				stepcnt[newHorizontal][newVertical]=
					stepcnt[horizontal][vertical]+1;
				if(labyrinth[newHorizontal][newVertical]=='e')
				{
					exitcnt++;
					if(stepcnts==-1)
					stepcnts=stepcnt[newHorizontal][newVertical];
				}
			}
		}
	}
	if(exitcnt)
	{
		cout<<exitcnt<<" ";
		return stepcnts;
	}
	return -1;
}
int main()
{
	cin>>n>>m;

	int x=-1,y=-1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>labyrinth[i][j];
			if(labyrinth[i][j]=='k')
			{
				x=i;y=j;//标记初始位置
			}
		}
	}
	memset(stepcnt,-1,sizeof(stepcnt));
	if(x==-1&&y==-1)
	{
		//此时题目错误，未进行进入
	}

	cout<<bfs(x,y)<<endl;
}